//
//  AppSetting.swift
//  MyKC
//
//  Created by yy on 2017/1/20.
//  Copyright © 2017年 com.yasuo. All rights reserved.
//

import UIKit
let shareAppSetting = AppSetting()
class AppSetting: NSObject {
    var userDefault: UserDefaults?
    override init() {
        userDefault = UserDefaults()
    }
    
    var _accessToken: String?
    var accessToken: String? {
        get {
            return userDefault?.value(forKey: "AccessToken") as! String?
        }
        set {
            _accessToken = newValue
            userDefault?.set(newValue, forKey: "AccessToken")
            userDefault?.synchronize()
        }
    }
    
    var _userName: String?
    var userName: String? {
        get {
            return userDefault?.value(forKey: "UserName") as! String?
        }
        set {
            _userName = newValue
            userDefault?.set(newValue, forKey: "UserName")
            userDefault?.synchronize()
        }
    }
    
    var userType: String? {
        get {
            return userDefault?.value(forKey: "UserType") as! String?
        }
        set {
            userDefault?.set(newValue, forKey: "UserType")
            userDefault?.synchronize()
        }
    }
    var password: String? {
        get {
            return userDefault?.value(forKey: "Password") as! String?
        }
        set {
            userDefault?.set(newValue, forKey: "Password")
            userDefault?.synchronize()
        }
    }
    var keepLogin: Bool {
        get {
            return (userDefault?.bool(forKey: "KeepLogin"))!
        }
        set {
            userDefault?.set(newValue, forKey: "KeepLogin")
            userDefault?.synchronize()
        }
    }
    
    var _storeId: String?
    var storeId: String? {
        get {
            return userDefault?.value(forKey: "StoreId") as! String?
        }
        set {
            _storeId = newValue
            userDefault?.set(newValue, forKey: "StoreId")
            userDefault?.synchronize()
        }
    }
}
